<!DOCTYPE html>
<html  lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
	<th:block th:include="include :: header('首页')" />
	<th:block th:include="include :: select2-css" />
</head>

<body class="gray-bg">
    <body class="gray-bg">
	<div class="container-div">
		<div class="row">
			<div class="btn-group-sm" id="toolbar" role="group">
				<a class="btn btn-success" id="team_pp">
	                <i class="fa fa-plus"></i> 开始匹配
	            </a>
	        </div>
	        
	        <div class="col-sm-12 select-table table-striped">
			    <table id="bootstrap-table"></table>
			</div>
		</div>
	</div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: select2-js" />
    <script th:inline="javascript">
    	var prefix = ctx + "system/manager";
    	var hgTeams = [];
    	
		$(function() {
		    var options = {
		        url: prefix + "/team/pp/list",
		        modalName: "队伍匹配",
		        height: 700,
		        pagination: false,
		        showToggle: false,
		        showRefresh: false,
		        showColumns: false,
		        showSearch: false,
		        columns: [{
		            checkbox: true
		        },
		        {
		            field: '500_team',
		            title: '500队名'
		        },
		        {
		            field: 'hg_team',
		            title: '皇冠队名',
		            formatter: function (value, row, index) {
		            	if(value) return value;
		            	var html_ = [];
		            	html_.push('<select name="team" class="team form-control noselect2 selectpicker">');
		            	html_.push('	<option value="">--请选择--</option>');
		            	for(var i=0;i<hgTeams.length; i++){
		            		html_.push('	<option value="'+hgTeams[i]+'">'+hgTeams[i]+'</option>');	
		            	}
						html_.push('</select>');
		        		return html_.join('\r\n');
		        	}
		        },
		        {
		            field: 'ls_name',
		            title: '联赛名'
		        }]
		    };
		    var getHgTeams = function(result) {
				hgTeams = result.data;
				$.table.init(options);
				setTimeout(() => {
					$('.team').select2();
				}, 1000);
			};
		    $.operate.post(prefix+"/team/list",{},getHgTeams,null,null);
		});
		
		$('#team_pp').on('click', function(){
			var url = prefix + "/team/pp/add";
			var datas = [];
			var rows = $('#bootstrap-table').bootstrapTable('getSelections');
			var hgselects = $('.team');
			if(rows==null || rows.length<1) return $.modal.msgWarning("请勾选匹配队伍!");
			var row;
			for(var i=0; i<rows.length; i++){
				row = rows[i];
				if(row.hg_team==null||row.hg_team=="") {
					var hg_team = $(hgselects[i]).find("option:selected").val();
					if(hg_team==null||hg_team=="") continue;
					row.hg_team = hg_team.split("_")[0];
				}
				var data_ = {
						dictType: "sys_team_name",
				};
				data_.status=0;
				data_.isDefault="N";
				data_.dictSort=0;
				data_.dictLabel=row["500_team"];
				data_.dictValue=row.hg_team;
				datas.push(JSON.stringify(data_));
			}
			$.operate.post(url,{
				dList: datas.join("#")
			},function(){
				$.table.search();
				setTimeout(() => {
					$('.team').select2();
				}, 1000);
			},null,null);
		});
    </script>
</body>
</html>
